package com.yeban.bams.entity;

import com.yeban.bams.exception.BalanceNotEnoughException;

/**
 * @Desc TODO
 * @Author yeban
 * @Date 2025/10/10
 *
 * 0 - 储蓄账户
 * 不允许透支，不允许贷款
 */
public class SavingAccount extends Account {

    private static final long serialVersionUID = 7517373551340227233L;

    public SavingAccount() {
    }

    public SavingAccount(Long id, String password, String name, String personId, String email, double balance) {
        super(id, password, name, personId, email, balance);
        this.setType(0);
    }

    /**
     * 取款
     * @param money
     * @return
     */
    @Override
    public Account withdraw(double money) throws BalanceNotEnoughException {
        if (this.getBalance() >= money) {   // 钱够
            setBalance(this.getBalance() - money);
            return this;
        }
        throw new BalanceNotEnoughException("您的账户余额不足");
    }
}

